package view;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import model.PengendaliPendaftaranYudisium;
import model.Yudisium;

public class PanelDaftarYudisium extends JPanel {

    private JLabel labelNama;
    private JTextField textNama;
    private JLabel labelNim;
    private JTextField textNim;
    private JLabel labelNoHp;
    private JTextField textNoHp;
    private JLabel labelEmail;
    private JTextField textEmail;
    private JLabel labelProdi;
    private JRadioButton radioTE;
    private JRadioButton radioTM;
    private JRadioButton radioTI;
    private JRadioButton radioMat;
    private JLabel labelPeriode;
    private JTextField textPeriode;
    private JLabel labelHari;
    private JTextField textHari;
    private JLabel labelTanggal;
    private JTextField textTanggal;
    private JLabel labelJudul;
    private JLabel labelDaftarNilai;
    private JCheckBox cekDaftarNilai;
    private JLabel labelNaskahTa;
    private JCheckBox cekNaskahTa;
    private JLabel labelBebasPinjamLab;
    private JCheckBox cekBebasPinjamLab;
    private JLabel labelBebasPinjamDosen;
    private JCheckBox cekBebasPinjamDosen;
    private JLabel labelBuktiKp;
    private JCheckBox cekBuktiKp;
    private JLabel labelTkbi;
    private JCheckBox cekTkbi;
    private JLabel labelPengesahanTa;
    private JCheckBox cekPengesahanTa;
    private JLabel labelRbm;
    private JCheckBox cekRbm;
    private JLabel labelpoint;
    private JCheckBox cekPoint;
    private JButton butonSimpan;
    private JButton butonBatal;

    public PanelDaftarYudisium() {
        this.setLayout(null);
        this.setBackground(Color.WHITE);

        labelJudul = new JLabel("FORM PENDAFTARAN YUDISIUM");
        labelJudul.setBounds(250, 5, 900, 48);
        labelJudul.setFont(new Font("Times New Roman", 3, 24));
        labelJudul.setHorizontalAlignment((int) CENTER_ALIGNMENT);
        this.add(labelJudul);


        labelNama = new JLabel("Nama");
        labelNama.setBounds(10, 70, 50, 50);
        this.add(labelNama);

        textNama = new JTextField();
        textNama.setBounds(95, 85, 350, 20);
        this.add(textNama);


        labelNim = new JLabel("NIM");
        labelNim.setBounds(10, 105, 50, 50);
        this.add(labelNim);

        textNim = new JTextField();
        textNim.setBounds(95, 120, 100, 20);
        this.add(textNim);


        labelNoHp = new JLabel("Telp/Email");
        labelNoHp.setBounds(10, 140, 75, 50);
        this.add(labelNoHp);

        textNoHp = new JTextField();
        textNoHp.setBounds(95, 155, 200, 20);
        this.add(textNoHp);

        labelEmail = new JLabel("/");
        labelEmail.setBounds(320, 140, 5, 50);
        this.add(labelEmail);

        textEmail = new JTextField();
        textEmail.setBounds(340, 155, 200, 20);
        this.add(textEmail);

        labelProdi = new JLabel("Prodi");
        labelProdi.setBounds(10, 175, 50, 50);
        this.add(labelProdi);

        radioTE = new JRadioButton("TE");
        radioTE.setBounds(95, 190, 50, 20);
        radioTM = new JRadioButton("TM");
        radioTM.setBounds(165, 190, 50, 20);
        radioTI = new JRadioButton("TI");
        radioTI.setBounds(235, 190, 50, 20);
        radioMat = new JRadioButton("MAT");
        radioMat.setBounds(305, 190, 50, 20);
        add(radioTE);
        add(radioTM);
        add(radioTI);
        add(radioMat);
        ButtonGroup radioGroup = new ButtonGroup();
        radioGroup.add(radioTE);
        radioGroup.add(radioTM);
        radioGroup.add(radioTI);
        radioGroup.add(radioMat);


        labelPeriode = new JLabel("Mendaftarkan Yudisium periode bulan");
        labelPeriode.setBounds(10, 240, 250, 50);
        this.add(labelPeriode);

        textPeriode = new JTextField();
        textPeriode.setBounds(230, 255, 75, 20);
        this.add(textPeriode);

        labelPeriode = new JLabel("yang diselenggarakan pada:");
        labelPeriode.setBounds(310, 240, 200, 50);
        this.add(labelPeriode);


        labelHari = new JLabel("Hari");
        labelHari.setBounds(50, 300, 50, 50);
        this.add(labelHari);

        textHari = new JTextField();
        textHari.setBounds(135, 315, 100, 20);
        this.add(textHari);

        labelTanggal = new JLabel("Tanggal");
        labelTanggal.setBounds(50, 335, 50, 50);
        this.add(labelTanggal);

        textTanggal = new JTextField();
        textTanggal.setBounds(135, 350, 200, 20);
        this.add(textTanggal);


        labelJudul = new JLabel("LAMPIRAN");
        labelJudul.setBounds(1000, 70, 300, 50);
        add(labelJudul);

        labelDaftarNilai = new JLabel("Daftar nilai yang telah disetujui oleh Dosen Pembimbing Akademik.");
        labelDaftarNilai.setBounds(850, 100, 500, 50);
        add(labelDaftarNilai);

        labelNaskahTa = new JLabel("Satu (1) naskah TA/Skripsi sudah dijilid dan ditandatangani oleh Dekan + Softcopy.");
        labelNaskahTa.setBounds(850, 132, 500, 50);
        add(labelNaskahTa);

        labelBebasPinjamLab = new JLabel("Surat keterangan bebas pinjaman dari Laboratorium Jurusan.");
        labelBebasPinjamLab.setBounds(850, 164, 500, 50);
        add(labelBebasPinjamLab);

        labelBebasPinjamDosen = new JLabel("Surat keterangan bebas pinjaman dari Dosen-dosen Jurusan.");
        labelBebasPinjamDosen.setBounds(850, 196, 500, 50);
        add(labelBebasPinjamDosen);

        labelBuktiKp = new JLabel("Bukti penyerahan laporan Kerja Praktek.");
        labelBuktiKp.setBounds(850, 228, 500, 50);
        add(labelBuktiKp);

        labelTkbi = new JLabel("Fotocopy keterangan TOEFL/Test Kompetensi Bahasa Inggris (TKBI).");
        labelTkbi.setBounds(850, 260, 500, 50);
        add(labelTkbi);

        labelPengesahanTa = new JLabel("Fotocopy Lembar Pengesahan Tugas Akhir (Khusus Prodi TI).");
        labelPengesahanTa.setBounds(850, 292, 500, 50);
        add(labelPengesahanTa);

        labelpoint = new JLabel("Sistem Poin (mahasiswa angkatan >= 2008.");
        labelpoint.setBounds(850, 324, 500, 50);
        add(labelpoint);

        labelRbm = new JLabel("Bukti penyerahan RBM (khusus Prodi TM).");
        labelRbm.setBounds(850, 356, 500, 50);
        add(labelRbm);

        cekDaftarNilai = new JCheckBox();
        cekDaftarNilai.setBounds(800, 100, 30, 50);
        add(cekDaftarNilai);

        cekNaskahTa = new JCheckBox();
        cekNaskahTa.setBounds(800, 132, 30, 50);
        add(cekNaskahTa);

        cekBebasPinjamLab = new JCheckBox();
        cekBebasPinjamLab.setBounds(800, 164, 30, 50);
        add(cekBebasPinjamLab);

        cekBebasPinjamDosen = new JCheckBox();
        cekBebasPinjamDosen.setBounds(800, 196, 30, 50);
        add(cekBebasPinjamDosen);

        cekBuktiKp = new JCheckBox();
        cekBuktiKp.setBounds(800, 228, 30, 50);
        add(cekBuktiKp);

        cekTkbi = new JCheckBox();
        cekTkbi.setBounds(800, 260, 30, 50);
        add(cekTkbi);

        cekPengesahanTa = new JCheckBox();
        cekPengesahanTa.setBounds(800, 292, 30, 50);
        add(cekPengesahanTa);

        cekPoint = new JCheckBox();
        cekPoint.setBounds(800, 324, 30, 50);
        add(cekPoint);

        cekRbm = new JCheckBox();
        cekRbm.setBounds(800, 356, 30, 50);
        add(cekRbm);


        butonSimpan = new JButton("Simpan");
        butonSimpan.setBounds(500, 600, 110, 50);
        add(butonSimpan);
        butonSimpan.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                tombolSimpanAction();
            }
        });
        butonBatal = new JButton("Batal");
        butonBatal.setBounds(650, 600, 110, 50);
        add(butonBatal);
        butonBatal.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                tombolBatalAction();
            }
        });
    }

    public void tombolSimpanAction() {
        Yudisium yud = new Yudisium();
                yud.setNim(getTextNim().getText());
        if (getRadioTE().isSelected()) {
                    yud.setProdi("Teknik Elektro");
                } else if (getRadioTM().isSelected()) {
                    yud.setProdi("Teknik Mesin");
                } else if (getRadioTI().isSelected()) {
                    yud.setProdi("Teknik Informatika");
                } else if (getRadioMat().isSelected()) {
                    yud.setProdi("Matematika Murni");
                }
        if (textNim.getText().isEmpty() && textNama.getText().isEmpty() && yud.getProdi()==null) {
            try {
                throw new Exception("Nim,nama,dan prodi harus terisi");
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage());
                Logger.getLogger(PanelLihatYudisium.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            if (textNim.getText().isEmpty()) {
                if (textNama.getText().isEmpty()) {
                    try {
                        throw new Exception("Nim dan nama harus terisi");
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                        Logger.getLogger(PanelLihatYudisium.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else if (yud.getProdi()==null) {
                    try {
                        throw new Exception("Nim dan prodi harus terisi");
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                        Logger.getLogger(PanelLihatYudisium.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    try {
                        throw new Exception("Nim harus terisi");
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                        Logger.getLogger(PanelLihatYudisium.class.getName()).log(Level.SEVERE, null, ex);

                    }
                }
            } else if (textNama.getText().isEmpty()) {
                if (textNim.getText().isEmpty()) {
                    try {
                        throw new Exception("Nim dan nama harus terisi");
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                        Logger.getLogger(PanelLihatYudisium.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else if (yud.getProdi()==null) {
                    try {
                        throw new Exception("Nama dan prodi harus terisi");
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                        Logger.getLogger(PanelLihatYudisium.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    try {
                        throw new Exception("Nama harus terisi");
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                        Logger.getLogger(PanelLihatYudisium.class.getName()).log(Level.SEVERE, null, ex);

                    }
                }
            } else if (yud.getProdi()==null) {
                if (textNim.getText().isEmpty()) {
                    try {
                        throw new Exception("Nim dan prodi harus terisi");
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                        Logger.getLogger(PanelLihatYudisium.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else if (textNama.getText().isEmpty()) {
                    try {
                        throw new Exception("Nama dan prodi harus terisi");
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                        Logger.getLogger(PanelLihatYudisium.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    try {
                        throw new Exception("Prodi harus terisi");
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                        Logger.getLogger(PanelLihatYudisium.class.getName()).log(Level.SEVERE, null, ex);

                    }
                }
            } else {
                if(yud.getNim().length()!=9) {

                }else {

                yud.setNama(getTextNama().getText());
                yud.setNoHp(getTextNoHp().getText());
                yud.setEmail(getTextEmail().getText());
                yud.setPeriode(getTextPeriode().getText());
                yud.setHari(getTextHari().getText());
                yud.setTanggal(Integer.parseInt(getTextTanggal().getText()));

//                if (getRadioTE().isSelected()) {
//                    yud.setProdi("Teknik Elektro");
//                } else if (getRadioTM().isSelected()) {
//                    yud.setProdi("Teknik Mesin");
//                } else if (getRadioTI().isSelected()) {
//                    yud.setProdi("Teknik Informatika");
//                } else if (getRadioMat().isSelected()) {
//                    yud.setProdi("Matematika Murni");
//                }


                if (getCekDaftarNilai().isSelected() == true) {
                    yud.setPersetujuan_nilai("Ada");
                } else {
                    yud.setPersetujuan_nilai("Tidak Ada");
                }


                if (getCekNaskahTa().isSelected() == true) {
                    yud.setPengesahan_skripsi("Ada");
                } else {
                    yud.setPengesahan_skripsi("Tidak Ada");
                }


                if (getCekBebasPinjamLab().isSelected() == true) {
                    yud.setBebaspinjam_lab("Ada");
                } else {
                    yud.setBebaspinjam_lab("Tidak Ada");
                }


                if (getCekBebasPinjamDosen().isSelected() == true) {
                    yud.setBebaspinjam_dosen("Ada");
                } else {
                    yud.setBebaspinjam_dosen("Tidak Ada");
                }


                if (getCekBuktiKp().isSelected() == true) {
                    yud.setBukti_kp("Ada");
                } else {
                    yud.setBukti_kp("Tidak Ada");
                }


                if (getCekTkbi().isSelected() == true) {
                    yud.setFotocopy_tkbi("Ada");
                } else {
                    yud.setFotocopy_tkbi("Tidak Ada");
                }


                if (getCekPengesahanTa().isSelected() == true) {
                    yud.setFotocopy_ta("Ada");
                } else {
                    yud.setFotocopy_ta("Tidak Ada");
                }


                if (getCekPoint().isSelected() == true) {
                    yud.setSistem_poin("Ada");
                } else {
                    yud.setSistem_poin("Tidak Ada");
                }


                if (getCekRbm().isSelected() == true) {
                    yud.setBukti_rbm("Ada");
                } else {
                    yud.setBukti_rbm("Tidak Ada");
                }
                yud.setStatus("Belum Di Verifikasi");


                JOptionPane.showMessageDialog(this, "Data Mahasiswa" + "\n\nNama: " + yud.getNama()
                        + "\nNim: " + yud.getNim() + "\nNo Hp: " + yud.getNoHp()
                        + "\nEmail: " + yud.getEmail() + "\nProdi: " + yud.getProdi()
                        + "\nPeriode: " + yud.getPeriode() + "\nHari: "
                        + yud.getHari() + "\nTanggal: " + yud.getTanggal() + "\nStatus: " + yud.getStatus());

                PengendaliPendaftaranYudisium.tambahMahasiswa(yud);
                PengendaliPendaftaranYudisium.tambahTabelMahasiswa(yud);
            }}
        }
    }

    public void tombolBatalAction() {
        System.exit(0);
    }

    public JLabel getLabelNama() {
        return labelNama;
    }

    public void setLabelNama(JLabel labelNama) {
        this.labelNama = labelNama;
    }

    public JTextField getTextNama() {
        return textNama;
    }

    public void setTextNama(JTextField textNama) {
        this.textNama = textNama;
    }

    public JLabel getLabelNim() {
        return labelNim;
    }

    public void setLabelNim(JLabel labelNim) {
        this.labelNim = labelNim;
    }

    public JTextField getTextNim() {
        return textNim;
    }

    public void setTextNim(JTextField textNim) {
        this.textNim = textNim;
    }

    public JLabel getLabelNoHp() {
        return labelNoHp;
    }

    public void setLabelNoHp(JLabel labelNoHp) {
        this.labelNoHp = labelNoHp;
    }

    public JTextField getTextNoHp() {
        return textNoHp;
    }

    public void setTextNoHp(JTextField textNoHp) {
        this.textNoHp = textNoHp;
    }

    public JLabel getLabelEmail() {
        return labelEmail;
    }

    public void setLabelEmail(JLabel labelEmail) {
        this.labelEmail = labelEmail;
    }

    public JTextField getTextEmail() {
        return textEmail;
    }

    public void setTextEmail(JTextField textEmail) {
        this.textEmail = textEmail;
    }

    public JLabel getLabelProdi() {
        return labelProdi;
    }

    public void setLabelProdi(JLabel labelProdi) {
        this.labelProdi = labelProdi;
    }

    public JRadioButton getRadioTE() {
        return radioTE;
    }

    public void setRadioTE(JRadioButton radioTE) {
        this.radioTE = radioTE;
    }

    public JRadioButton getRadioTM() {
        return radioTM;
    }

    public void setRadioTM(JRadioButton radioTM) {
        this.radioTM = radioTM;
    }

    public JRadioButton getRadioTI() {
        return radioTI;
    }

    public void setRadioTI(JRadioButton radioTI) {
        this.radioTI = radioTI;
    }

    public JRadioButton getRadioMat() {
        return radioMat;
    }

    public void setRadioMat(JRadioButton radioMat) {
        this.radioMat = radioMat;
    }

    public JLabel getLabelPeriode() {
        return labelPeriode;
    }

    public void setLabelPeriode(JLabel labelPeriode) {
        this.labelPeriode = labelPeriode;
    }

    public JTextField getTextPeriode() {
        return textPeriode;
    }

    public void setTextPeriode(JTextField textPeriode) {
        this.textPeriode = textPeriode;
    }

    public JLabel getLabelHari() {
        return labelHari;
    }

    public void setLabelHari(JLabel labelHari) {
        this.labelHari = labelHari;
    }

    public JTextField getTextHari() {
        return textHari;
    }

    public void setTextHari(JTextField textHari) {
        this.textHari = textHari;
    }

    public JLabel getLabelTanggal() {
        return labelTanggal;
    }

    public void setLabelTanggal(JLabel labelTanggal) {
        this.labelTanggal = labelTanggal;
    }

    public JTextField getTextTanggal() {
        return textTanggal;
    }

    public void setTextTanggal(JTextField textTanggal) {
        this.textTanggal = textTanggal;
    }

    public JLabel getLabelJudul() {
        return labelJudul;
    }

    public void setLabelJudul(JLabel labelJudul) {
        this.labelJudul = labelJudul;
    }

    public JLabel getLabelDaftarNilai() {
        return labelDaftarNilai;
    }

    public void setLabelDaftarNilai(JLabel labelDaftarNilai) {
        this.labelDaftarNilai = labelDaftarNilai;
    }

    public JCheckBox getCekDaftarNilai() {
        return cekDaftarNilai;
    }

    public void setCekDaftarNilai(JCheckBox cekDaftarNilai) {
        this.cekDaftarNilai = cekDaftarNilai;
    }

    public JLabel getLabelNaskahTa() {
        return labelNaskahTa;
    }

    public void setLabelNaskahTa(JLabel labelNaskahTa) {
        this.labelNaskahTa = labelNaskahTa;
    }

    public JCheckBox getCekNaskahTa() {
        return cekNaskahTa;
    }

    public void setCekNaskahTa(JCheckBox cekNaskahTa) {
        this.cekNaskahTa = cekNaskahTa;
    }

    public JLabel getLabelBebasPinjamLab() {
        return labelBebasPinjamLab;
    }

    public void setLabelBebasPinjamLab(JLabel labelBebasPinjamLab) {
        this.labelBebasPinjamLab = labelBebasPinjamLab;
    }

    public JCheckBox getCekBebasPinjamLab() {
        return cekBebasPinjamLab;
    }

    public void setCekBebasPinjamLab(JCheckBox cekBebasPinjamLab) {
        this.cekBebasPinjamLab = cekBebasPinjamLab;
    }

    public JLabel getLabelBebasPinjamDosen() {
        return labelBebasPinjamDosen;
    }

    public void setLabelBebasPinjamDosen(JLabel labelBebasPinjamDosen) {
        this.labelBebasPinjamDosen = labelBebasPinjamDosen;
    }

    public JCheckBox getCekBebasPinjamDosen() {
        return cekBebasPinjamDosen;
    }

    public void setCekBebasPinjamDosen(JCheckBox cekBebasPinjamDosen) {
        this.cekBebasPinjamDosen = cekBebasPinjamDosen;
    }

    public JLabel getLabelBuktiKp() {
        return labelBuktiKp;
    }

    public void setLabelBuktiKp(JLabel labelBuktiKp) {
        this.labelBuktiKp = labelBuktiKp;
    }

    public JCheckBox getCekBuktiKp() {
        return cekBuktiKp;
    }

    public void setCekBuktiKp(JCheckBox cekBuktiKp) {
        this.cekBuktiKp = cekBuktiKp;
    }

    public JLabel getLabelTkbi() {
        return labelTkbi;
    }

    public void setLabelTkbi(JLabel labelTkbi) {
        this.labelTkbi = labelTkbi;
    }

    public JCheckBox getCekTkbi() {
        return cekTkbi;
    }

    public void setCekTkbi(JCheckBox cekTkbi) {
        this.cekTkbi = cekTkbi;
    }

    public JLabel getLabelPengesahanTa() {
        return labelPengesahanTa;
    }

    public void setLabelPengesahanTa(JLabel labelPengesahanTa) {
        this.labelPengesahanTa = labelPengesahanTa;
    }

    public JCheckBox getCekPengesahanTa() {
        return cekPengesahanTa;
    }

    public void setCekPengesahanTa(JCheckBox cekPengesahanTa) {
        this.cekPengesahanTa = cekPengesahanTa;
    }

    public JLabel getLabelRbm() {
        return labelRbm;
    }

    public void setLabelRbm(JLabel labelRbm) {
        this.labelRbm = labelRbm;
    }

    public JCheckBox getCekRbm() {
        return cekRbm;
    }

    public void setCekRbm(JCheckBox cekRbm) {
        this.cekRbm = cekRbm;
    }

    public JLabel getLabelpoint() {
        return labelpoint;
    }

    public void setLabelpoint(JLabel labelpoint) {
        this.labelpoint = labelpoint;
    }

    public JCheckBox getCekPoint() {
        return cekPoint;
    }

    public void setCekPoint(JCheckBox cekPoint) {
        this.cekPoint = cekPoint;
    }

    public JButton getButonSimpan() {
        return butonSimpan;
    }

    public void setButonSimpan(JButton butonSimpan) {
        this.butonSimpan = butonSimpan;
    }

    public JButton getButonBatal() {
        return butonBatal;
    }

    public void setButonBatal(JButton butonBatal) {
        this.butonBatal = butonBatal;
    }
}
